package com.chezhujie.www.service;

import com.chezhujie.www.domain.Czjdataresource;
import com.chezhujie.www.persistence.CzjdataresourceMapper;
import com.xy.core.exception.ClassCheckException;
import com.xy.user.base.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 数据资源
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class CzjdataresourceService extends BaseService<Czjdataresource> {
    @Autowired
    private CzjdataresourceMapper czjdataresourceMapper;

    @Autowired
    public void setBaseMapper(CzjdataresourceMapper czjdataresourceMapper) {
        this.baseMapper = czjdataresourceMapper;
    }


    public void checkEntity(Czjdataresource czjdataresource) throws ClassCheckException {
        if (czjdataresource.getDataresourceId() != null && czjdataresource.getDataresourceId().length() > 19) {
            throw new ClassCheckException("数据资源主键不能超过19个字符");
        }
        if (czjdataresource.getCode() != null && czjdataresource.getCode().length() > 10) {
            throw new ClassCheckException("数据资源编码不能超过10个字符");
        }
        if (czjdataresource.getCodename() != null && czjdataresource.getCodename().length() > 50) {
            throw new ClassCheckException("数据资源编码名称不能超过50个字符");
        }
        if (czjdataresource.getName() != null && czjdataresource.getName().length() > 50) {
            throw new ClassCheckException("数据资源名称不能超过50个字符");
        }
        if (czjdataresource.getValue() != null && czjdataresource.getValue().length() > 255) {
            throw new ClassCheckException("数据资源值不能超过255个字符");
        }
        if (czjdataresource.getTitle() != null && czjdataresource.getTitle().length() > 50) {
            throw new ClassCheckException("数据资源编码标题不能超过50个字符");
        }
    }

    public void checkListEntity(List<Czjdataresource> listCzjdataresource) throws ClassCheckException {

        for (Czjdataresource czjdataresource : listCzjdataresource) {
            checkEntity(czjdataresource);
        }

    }

    public Czjdataresource queryByCode(String code) {
        return czjdataresourceMapper.queryByCode(code);
    }
}
